#include<iostream>

using namespace std;

#include "modbus.h"
#include "../device/device.h"
#include "../slave/server.h"
#include "sysconfig.h"
#include "channel.h"

#include "spdlog/spdlog.h"
//#include "clog.hpp"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/async.h"
#include "spdlog/logger.h"

bool s_gRun = false;
int main(int argc, char*argv[])
{
    auto l= spdlog::rotating_logger_mt("L->", "e.log", 1048576 * 50, 3);
    spdlog::set_default_logger(l);
    spdlog::set_level(spdlog::level::info);
    spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] %v");
    spdlog::flush_every(std::chrono::seconds(1));
    spdlog::info("Welcome to egateway!");

    sysconfig::init();
    //dps 填充slave
    mbserver_mgr::getInstance()->init_dpsset_fromchannelmgr(sysconfig::m_channelmgr.get_param());
    devicemgr_module::getInstance()->init();
    mbserver_mgr::getInstance()->init();

    //采集
    sysconfig::m_channelmgr.start();
    devicemgr_module::getInstance()->start();
    mbserver_mgr::getInstance()->start();
   int itt = 0;
   sysconfig::close_confdb();
   s_gRun =  true;
   while (s_gRun)
   {
      std::this_thread::sleep_for(std::chrono::milliseconds(100));
   }
    return 0;
}